//
//  DCNewDriverViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/1.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCNewDriverViewController.h"
#import "DCImageAndTextFieldView.h"
#import "DCIDCardImagePicker.h"
@interface DCNewDriverViewController ()<TZImagePickerControllerDelegate>
@property (nonatomic,strong) DCImageAndTextFieldView *nameView;
@property (nonatomic,strong) DCImageAndTextFieldView *IdCardView;
@property (nonatomic,strong) DCImageAndTextFieldView *phoneView;
@property (nonatomic,strong) DCImageAndTextFieldView *plateView;
@end

@implementation DCNewDriverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"新增司机";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setUpMainUI];
}
-(void)setUpMainUI {
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, ScreenHeight - navHeight-statusHeight - 40)];
    scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:scrollView];
    
    self.nameView = [DCImageAndTextFieldView creatViewWithFrame:CGRectMake(10, 10, self.view.width-20, 40) image:IMAGENAME(@"name") imageShape:ImageIsSquare imageHeight:30 placeholder:@"请输入司机姓名" isEdit:YES];
    [scrollView addSubview:self.nameView];
    
    self.IdCardView = [DCImageAndTextFieldView creatViewWithFrame:CGRectMake(10, self.nameView.bottom+10, self.view.width-20, 40) image:IMAGENAME(@"身份证") imageShape:ImageIsRectangle imageHeight:25 placeholder:@"请输入司机身份证号" isEdit:YES];
    [scrollView addSubview:self.IdCardView];
    
    self.phoneView = [DCImageAndTextFieldView creatViewWithFrame:CGRectMake(10, self.IdCardView.bottom+10, self.view.width-20, 40) image:IMAGENAME(@"电话") imageShape:ImageIsSquare imageHeight:30 placeholder:@"请输入司机电话号" isEdit:YES];
    [scrollView addSubview:self.phoneView];
    
    self.plateView = [DCImageAndTextFieldView creatViewWithFrame:CGRectMake(10, self.phoneView.bottom+10, self.view.width-20, 40) image:IMAGENAME(@"车牌") imageShape:ImageIsRectangle imageHeight:25 placeholder:@"请选择关联车牌号" isEdit:NO];
    [scrollView addSubview:self.plateView];
    
    CGFloat kMargin = 13;
    CGFloat btnW = (self.view.width - kMargin*3)/2;
    CGFloat btnH = 130*HEIGHTSCALE6;
    __weak typeof(self) weakself = self;
    
    DCIDCardImagePicker *firstImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin, self.plateView.bottom+20+kMargin, btnW, btnH)];
    firstImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"身份证(正面)" subStringColor:[UIColor blackColor] subString:@"身份证" andFont:FONT(16)];
    firstImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [scrollView addSubview:firstImageView];
    
    DCIDCardImagePicker *secondImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin+firstImageView.right, firstImageView.y, btnW, btnH)];
    secondImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"身份证(反面)" subStringColor:[UIColor blackColor] subString:@"身份证" andFont:FONT(16)];
    secondImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [scrollView addSubview:secondImageView];
    
    DCIDCardImagePicker *thirdImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(firstImageView.x, firstImageView.bottom+kMargin, btnW, btnH)];
    thirdImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"从业资格证" subStringColor:[UIColor blackColor] subString:@"从业资格证" andFont:FONT(16)];
    thirdImageView.block = ^(UIImageView * _Nonnull imageView) {
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
        
    };
    [scrollView addSubview:thirdImageView];
    
    DCIDCardImagePicker *forthImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(secondImageView.x, thirdImageView.y, btnW, btnH)];
    forthImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"从业资格证(副页)" subStringColor:[UIColor blackColor] subString:@"从业资格证" andFont:FONT(16)];
    forthImageView.block = ^(UIImageView * _Nonnull imageView) {
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
        
    };
    [scrollView addSubview:forthImageView];
    
    
    UIButton * surtBtn = [[UIButton alloc]init];
    [surtBtn setTitle:@"提交" forState:UIControlStateNormal];
    surtBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [surtBtn addTarget:self action:@selector(surtBtnOnClicked) forControlEvents:UIControlEventTouchUpInside];
    surtBtn.layer.cornerRadius = 20;
    surtBtn.layer.masksToBounds = YES;
    //    surtBtn.backgroundColor = BlueColor;
    surtBtn.layer.borderWidth = 1;
    surtBtn.layer.borderColor = BlueColor.CGColor;
    [surtBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    [self.view addSubview:surtBtn];
    [surtBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(35);
        make.left.equalTo(weakself.view.mas_left).offset(50);
        make.right.equalTo(weakself.view.mas_right).offset(-50);
        make.bottom.equalTo(weakself.view.mas_bottom).offset(-7);
    }];
    
    scrollView.contentSize = CGSizeMake(self.view.width, CGRectGetMaxY(forthImageView.frame)+40);
}

-(void)surtBtnOnClicked {
    
    DCLog(@"%@",self.nameView.textField.text);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
